<?php

namespace App\Http\Controllers;

use App\Utils\OptionUtil;
use Illuminate\Http\Request;

class OptionController extends BaseController
{
    public function getOptionAll(Request $request)
    {
        $data = [];
        $maps = [
            OptionUtil::OPTION_NAME_ORGANIZATION_CODE,
            OptionUtil::OPTION_NAME_CERTIFICATION,
            OptionUtil::OPTION_NAME_AGREEMENT_ORIGIN,
            OptionUtil::OPTION_NAME_AUDIT_TYPE,
        ];

        foreach ($maps as $val) {
            $options = [];
            foreach (OptionUtil::getOptionMap($val) as $k => $v) {
                $options[] = ['value' => $k, 'label' => $v];
            }

            $data[$val] = $options;
        }

        return self::responseJson($data);
    }

    public function getOptionByName(Request $request)
    {
        $data = OptionUtil::getOptionMap($request->get('name'));

        if (empty($data)) {
            return self::responseJson([
                OptionUtil::OPTION_NAME_ORGANIZATION_CODE,
                OptionUtil::OPTION_NAME_CERTIFICATION,
                OptionUtil::OPTION_NAME_AGREEMENT_ORIGIN,
                OptionUtil::OPTION_NAME_AUDIT_TYPE,
            ]);
        }

        $options = [];
        foreach ($data as $key => $val) {
            $options[] = [
                'value' => $key,
                'label' => $val
            ];
        }

        return self::responseJson($options);
    }
}
